import {
  applyAudit,
  approval,
  fileQueryPageList,
  queryApplyDetail,
  queryAuditPageList,
  queryNotPageList,
  queryDatadictList,
} from '@/services/workspace';

export default {
  namespace: 'auditModel',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
    hasdata: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
    detail: {},
    queryForm: {},

  },

  effects: {
    * queryAuditPageList({payload}, {call, put}) {
      const response = yield call(queryAuditPageList, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'save',
        payload: response,
      });
      }
    },
    //  查询申请详情
    * queryApplyDetail({payload}, {call, put}) {
      const response = yield call(queryApplyDetail, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'saveApplyDetail',
        payload: response,
      });
      }
    },

    * queryDatadict({payload, callback,}, {call, put}) {
      const response = yield call(queryDatadictList, payload);
      if (callback) callback(response);
    },



    //审批
    * applyAudit({payload, callback}, {call, put}) {
      const response = yield call(applyAudit, payload);
      if (callback) callback(response);
    },
    //文件审批列表
    * approval({payload, callback}, {call, put}) {
      const response = yield call(approval, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'saveapproval',
        payload: response,
      });
      }
      if (callback) callback(response);
    },
    //未审批列表**********这个接口废弃
    * queryNotPageList({payload, callback}, {call, put}) {
      const response = yield call(queryNotPageList, payload);
      if (response.result == "ok") {
        yield put({
          type: 'save',
          payload: response,
        });
      }

      if (callback) callback(response);
    },
    //已审批列表
    * fileQueryPageList({payload, callback}, {call, put}) {
      const response = yield call(fileQueryPageList, payload);
      if (response.result == "ok") {
        yield put({
          type: 'hassave',
          payload: response,
        });
      }

      if (callback) callback(response);
    },

  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
    hassave(state, action) {
      return {
        ...state,
        hasdata: action.payload.data,
      };
    },
    saveApplyDetail(state, action) {
      return {
        ...state,
        detail: action.payload.data,
      };
    },
  },
};
